import LoginUser from '@model/entity/LoginUser/LoginUser'
import { BatchAllotItemResult, getBatchAllotResult } from '@model/param/out/Task'
import { PLAN_TASK_MAX_PERFORM_NUMBER, PART_SERVICE_LIST_MAX_LENGTH, PART_SERVICE_LIST_PRENUM_MAX_LENGTH, MATERIAL_LIST_MAX } from '@src/model/const/Number'
import { strConcat as concat } from 'pub-bbx-utils';
import { isEmpty } from '@src/util/type';
import { t } from '@src/locales'

// 工单产品联系人地址不相同的提示
export const TASK_PRODUCT_LINKMAN_AND_ADDRESS_NOT_EQUAL_MESSAGE: string = t('common.modal.TASK_PRODUCT_LINKMAN_AND_ADDRESS_NOT_EQUAL_MESSAGE')
// 工单产品联系人不相同的提示
export const TASK_PRODUCT_LINKMAN_NOT_EQUAL_MESSAGE: string = t('common.modal.TASK_PRODUCT_LINKMAN_NOT_EQUAL_MESSAGE')
// 工单产品地址不相同的提示
export const TASK_PRODUCT_ADDRESS_NOT_EQUAL_MESSAGE: string = t('common.modal.TASK_PRODUCT_ADDRESS_NOT_EQUAL_MESSAGE')
// 计划任务计划时间必填提示
export const PLATN_TASK_PLAN_TIME_REQUIRES_MESSAGE: string = t('common.modal.PLATN_TASK_PLAN_TIME_REQUIRES_MESSAGE')
// 计划任务计划时间必填提示
export const TASK_NO_EXECUTOR_MESSAGE: string = t('common.modal.TASK_NO_EXECUTOR_MESSAGE')
// 服务商派单服务部门必填提示
export const TASK_SERVICE_DEPARTMENT_REQUIRES_MESSAGE: string = t('common.modal.TASK_SERVICE_DEPARTMENT_REQUIRES_MESSAGE')
// 在使用日历派单时必填 计划开始时间
export const TASK_NO_CALENDAR_START_TIME: string = t('common.modal.TASK_NO_CALENDAR_START_TIME')
// 在使用日历派单时必填 计划结束时间
export const TASK_NO_CALENDAR_END_TIME: string = t('common.modal.TASK_NO_CALENDAR_END_TIME')
// 计划任务重复周期不能为0
export const PLATN_TASK_PERIOD_NOT_ZERO_MESSAGE: string = t('common.modal.PLATN_TASK_PERIOD_NOT_ZERO_MESSAGE')
// 计划任务创建时间不得超过周期天数
export const PLATN_TASK_CREATE_TIME_NOT_GREATER_THEAN_PERIOD_TIME_MESSAGE: string = t('common.modal.PLATN_TASK_CREATE_TIME_NOT_GREATER_THEAN_PERIOD_TIME_MESSAGE')
// 计划任务截止日期不得超过1年
export const PLATN_TASK_END_TIME_NOT_GREATER_ONE_YEAR_MESSAGE: string = t('common.modal.PLATN_TASK_END_TIME_NOT_GREATER_ONE_YEAR_MESSAGE')
// 计划任务执行次数不能超过 PLAN_TASK_MAX_PERFORM_NUMBER
export const PLATN_TASK_PERFORM_NUMBER_MAX_MESSAGE: string = t('common.modal.PLATN_TASK_PERFORM_NUMBER_MAX_MESSAGE', { PLAN_TASK_MAX_PERFORM_NUMBER })
// 请选择产品
export const REQUIRES_PRODUCT_MESSAGE: string = t('common.modal.REQUIRES_PRODUCT_MESSAGE')
// 计划时间不能早于现在
export const PLAN_TIME_NOT_LESS_THEN_NOW_MEESSAGE: string = t('common.modal.PLAN_TIME_NOT_LESS_THEN_NOW_MEESSAGE')
// 计划开始时间不能早于现在
export const PLAN_START_TIME_NOT_LESS_THEN_NOW_MEESSAGE: string = t('common.modal.PLAN_START_TIME_NOT_LESS_THEN_NOW_MEESSAGE')
// 计划完成时间不能早于现在
export const PLAN_END_TIME_NOT_LESS_THEN_NOW_MEESSAGE: string = t('common.modal.PLAN_END_TIME_NOT_LESS_THEN_NOW_MEESSAGE')
// 计划完成时间不能早于计划开始时间
export const PLAN_END_TIME_NOT_LESS_THEN_PLAN_START_TIME_MEESSAGE: string = t('common.modal.PLAN_END_TIME_NOT_LESS_THEN_PLAN_START_TIME_MEESSAGE')
// 计划时间不能早于现在
export const REQUIRE_OTHER_NOTIFICATION_USER_MEESSAGE: string = t('common.modal.REQUIRE_OTHER_NOTIFICATION_USER_MEESSAGE')
// 工单指派地理位置 最大值不能小于最小值
export const MAX_GREATER_THAN__MIN_MESSAGE: string = t('common.modal.MAX_GREATER_THAN__MIN_MESSAGE')
// 工单指派地理位置 最大值不能小于最小值
export const REQUIRED_MIN_MESSAGE: string = t('common.modal.REQUIRED_MIN_MESSAGE')
// 工单指派地理位置 最大值不能小于最小值
export const REQUIRED_MAX_MESSAGE: string = t('common.modal.REQUIRED_MAX_MESSAGE')
// 转派说明必填提示
export const TASK_NO_REALLOT_REASON_MESSAGE: string = t('common.modal.TASK_NO_REALLOT_REASON_MESSAGE')
// 转派选择原因提示
export const TASK_NO_REALLOR_CUSTOMREASON: string = t('common.modal.TASK_NO_REALLOR_CUSTOMREASON')
// 不能将工单转派给原负责人
export const TASK_REALLOT_NOT_SAME_USER_MESSAGE: string = t('common.modal.TASK_REALLOT_NOT_SAME_USER_MESSAGE')
// 为匹配到分配规则
export const TASK_NOT_AUTO_DISPATCH_RULE: string = t('common.modal.TASK_NOT_AUTO_DISPATCH_RULE')
// 未找到上次派单结果
export const TASK_ALLOT_NOT_STORAGE_RESULT: string = t('common.modal.TASK_ALLOT_NOT_STORAGE_RESULT')
// 备件服务清单添加数量不能超过 PART_SERVICE_LIST_MAX_LENGTH
export const PART_SERVICE_LIST_MAX_LENGTH_MESSAGE: string = t('common.modal.PART_SERVICE_LIST_MAX_LENGTH_MESSAGE', { PART_SERVICE_LIST_MAX_LENGTH })
// 物料添加数量不能超过 MATERIAL_SERVICE_LIST_MAX
export const MATERIAL_LIST_MAX_LENGTH_MESSAGE: string = t('common.modal.MATERIAL_LIST_MAX_LENGTH_MESSAGE', { MATERIAL_LIST_MAX })
// 备件服务清单预计用量不能超过 PART_SERVICE_LIST_PRENUM_MAX_LENGTH
export const PART_SERVICE_LIST_PRENUM_MAX_LENGTH_MESSAGE: string = t('common.modal.PART_SERVICE_LIST_PRENUM_MAX_LENGTH_MESSAGE', { PART_SERVICE_LIST_PRENUM_MAX_LENGTH })
// 链接格式
export const LINK_START_ERROR_MESSAGE: string = t('common.modal.LINK_START_ERROR_MESSAGE')
// 选择数据
export const PLEASE_SELECT_DATA_MESSAGE: string = t('common.modal.PLEASE_SELECT_DATA_MESSAGE')
// 确认删除计划任务
export const CONFIRM_DELETE_PLAN_TASK_MESSAGE: string = t('common.modal.CONFIRM_DELETE_PLAN_TASK_MESSAGE')
// 删除成功
export const DELETE_SUCCESS_MESSAGE: string = t('common.modal.DELETE_SUCCESS_MESSAGE')
// 批量结算成功
export const BATCH_BALANCE_SUCCESS_MESSAGE: string = t('common.modal.BATCH_BALANCE_SUCCESS_MESSAGE')
// 批量关闭成功
export const BATCH_CLOSE_SUCCESS_MESSAGE: string = t('common.modal.BATCH_CLOSE_SUCCESS_MESSAGE')
// 确定关闭工单提示
export const CONFIRM_CLOSE_TASK_MESSAGE: string = t('common.modal.CONFIRM_CLOSE_TASK_MESSAGE')
// 关闭成功
export const CLOSE_SUCCESS_MESSAGE: string = t('common.modal.CLOSE_SUCCESS_MESSAGE')
// 对所选的工单列表发送回访短信
export const SEND_SELECTED_REVIEW_TASK_SMS_MESSAGE: string = t('common.modal.SEND_SELECTED_REVIEW_TASK_SMS_MESSAGE')
// 对所选的工单发送回访短信
export const REVIEW_TASK_SMS_MESSAGE: string = t('common.modal.REVIEW_TASK_SMS_MESSAGE')
// 未启用计划任务
export const NOT_OPEN_PLANTASK_MASSAGE: string = t('common.modal.NOT_OPEN_PLANTASK_MASSAGE')
// 未启用审核结算
export const NOT_OPEN_BALANCE_MASSAGE: string = t('common.modal.NOT_OPEN_BALANCE_MASSAGE')
// 未启用回访
export const NOT_REVIEW_MASSAGE: string = t('common.modal.NOT_REVIEW_MASSAGE')
// 未启用自动回访
export const NOT_AUTO_REVIEW_MASSAGE: string = t('common.modal.NOT_AUTO_REVIEW_MASSAGE')
// 转派成功添加部分协同人信息
export const ALLOT_SYNERGY_MASSAGE: string = t('common.modal.ALLOT_SYNERGY_MASSAGE')
// 批量指派为选择提示
export const ALLOT_TASK_REQUIRED_MASSAGE: string = t('common.modal.ALLOT_TASK_REQUIRED_MASSAGE')
// 批量调整计划时间成功
export const BATCH_UPDATE_PLANTIME_SUCCESS_MESSAGE: string = t('common.modal.BATCH_UPDATE_PLANTIME_SUCCESS_MESSAGE')
// 批量删除工单提示
export const BATCH_DELETE_TASK_MASSAGE = t('common.modal.BATCH_DELETE_TASK_MASSAGE')
// 选择要导出的数据
export const PLEASE_SELECT_EXPORT_DATA_MESSAGE = t('common.modal.PLEASE_SELECT_EXPORT_DATA_MESSAGE')
// 只可以添加保内产品
export const ONLY_SELECT_INQUALITY = t('common.modal.ONLY_SELECT_INQUALITY')
// 只可以添加一个产品
export const ONLY_SELECT_ONE_QUALITY = t('common.modal.ONLY_SELECT_ONE_QUALITY')
// 启用工单池派单功能
export const TASK_POOL_LIST_DISPATCHING_NOT_BEEN_ENABLED: string = t('common.modal.TASK_POOL_LIST_DISPATCHING_NOT_BEEN_ENABLED')
// 启用工单池派单功能
export const VALUE_EMPTY: string = t('common.modal.VALUE_EMPTY')
// 保存成功
export const SAVE_SUCCESS: string = t('common.modal.SAVE_SUCCESS')
// 修改成功
export const MODIFY_SUCCESS: string = t('common.modal.MODIFY_SUCCESS')
// 修改
export const MODIFY: string = t('common.modal.MODIFY')
// 聊天功能仅限企业微信客户端使用
export const ONLY_WORK_WX_CHAT: string = t('common.modal.ONLY_WORK_WX_CHAT')
// 复制成功
export const COPY_SUCCESS: string = t('common.modal.COPY_SUCCESS')
// 复制成功 (分享)
export const COPY_SHARE_ERROR: string = t('common.modal.COPY_SHARE_ERROR')
// 复制成功
export const COPY_PHONE_SUCCESS: string = t('common.modal.COPY_PHONE_SUCCESS')
// 复制成功 (分享)
export const COPY_ERROR: string = t('common.modal.COPY_ERROR')
// 复制内容
export const COPY_TEXT_CONTENT: string = t('common.modal.COPY_TEXT_CONTENT')
export const COPY_TEXT_MESSAGE: string = t('common.modal.COPY_TEXT_MESSAGE')

// 复制成功COPY_TEXT_MESSAGE
export const COPY_TEXT_SUCCESS: string = t('common.modal.COPY_TEXT_SUCCESS')
// 复制失败
export const COPY_TEXT_FIAL: string = t('common.modal.COPY_TEXT_FIAL')

export const PASS_WORD_MESSAGE = t('common.modal.PASS_WORD_MESSAGE')

export const RESTORE_SUCCESS_MESSAGE = t('common.modal.RESTORE_SUCCESS_MESSAGE')

export const ADD_SUCCESS_MESSAGE = t('common.modal.ADD_SUCCESS_MESSAGE')

export const REMOVE_SUCCESS_MESSAGE = t('common.modal.REMOVE_SUCCESS_MESSAGE')

export const REMOVE_ROLE_AUTH_SUCCESS_MESSAGE = t('common.modal.REMOVE_ROLE_AUTH_SUCCESS_MESSAGE')

export const ROLE_ALLOT_SUCCESS_MESSAGE = t('common.modal.ROLE_ALLOT_SUCCESS_MESSAGE')

export const RESET_SUCCESS_MESSAGE = t('common.modal.RESET_SUCCESS_MESSAGE')

export const DEFAULT_ROLE_ALLOT_AUTO_SAVE_ERROR_MESSAGE = t('common.modal.DEFAULT_ROLE_ALLOT_AUTO_SAVE_ERROR_MESSAGE')
export const DEFAULT_ROLE_ALLOT_AUTO_SAVE_SUCCESS_MESSAGE = t('common.modal.DEFAULT_ROLE_ALLOT_AUTO_SAVE_SUCCESS_MESSAGE')

export const BatchAllotNotExecutorSuccessMessage = function (
  succAllotList: BatchAllotItemResult[],
  synergyUsers: LoginUser[],
  exeInSynergyMessage: string
) {
  return (
    `${t('common.modal.BatchAllotNotExecutorSuccessMessage', { 
      successCount: succAllotList.length,
      synergyUsers: isEmpty(synergyUsers) ? t('common.base.null') : concat(synergyUsers.map(synergyUser => synergyUser.displayName || '')),
    })}\n${ exeInSynergyMessage}`
  )
}

export const BatchAllotExecutorSuccessMessage = function (
  succAllotList: BatchAllotItemResult[],
  synergyUsers: LoginUser[],
  executorUsers: LoginUser[],
  exeInSynergyMessage: string
) {
  return (
    `${t('common.modal.BatchAllotExecutorSuccessMessage', { 
      successCount: succAllotList.length,
      executorUsers: executorUsers?.[0].displayName || '',
      synergyUsers: isEmpty(synergyUsers) ? t('common.base.null') : concat(synergyUsers.map(synergyUser => synergyUser.displayName || '')),
    })}\n${exeInSynergyMessage}`
  )
}

export const BatchAllotPartSuccessMessage = function (
  result: getBatchAllotResult
) {
  const succAllotList: BatchAllotItemResult[] = result?.data?.succ || []
  const failAllotList: BatchAllotItemResult[] = result?.data?.fail || []
  
  function failTaskNoMessage(failAllotList: BatchAllotItemResult[]): string {
    let messages: string[] = []
    let message: string = ''
    
    failAllotList.forEach((failAllotListItem, index) => {
      message = failAllotListItem.taskNo
      
      messages.push(message)
    })
    
    return concat(messages)
  }
  
  return (
    `${result.message} : ${failTaskNoMessage(failAllotList)} ${t('common.modal.BatchAllotPartSuccessMessage', { successCount: succAllotList.length })}`
  )
}

// 批量关闭工单提示
export const BatchCloseTaskMessage: (number: number) => string = (number: number) => t('common.modal.BatchCloseTaskMessage', { number })

// 批量删除工单错误提示
export const BatchDeleteTaskErrorMessage: (message: string) => string = (message: string) => t('common.modal.BatchDeleteTaskErrorMessage', { message })
